package com.winsdom.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.winsdom.dto.FormulaDTO;
import com.winsdom.entity.Formula;
import com.winsdom.entity.vo.CustomerBillingHeaderVo;
import com.winsdom.mapper.FormulaMapper;
import com.winsdom.service.IFormulaService;
import com.winsdom.vo.FormulaVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 公式表 服务实现类
 * </p>
 *
 * @author
 * @since 2025-05-23
 */
@Service
public class FormulaServiceImpl extends ServiceImpl<FormulaMapper, Formula> implements IFormulaService {
    private static final Logger logger = LoggerFactory.getLogger(FormulaServiceImpl.class);

    @Autowired
    private FormulaMapper formulaMapper;

    @Override
    public IPage<FormulaVO> list(FormulaDTO formulaDTO) {
        try {
            IPage<FormulaVO> page = new Page<>(formulaDTO.getPageNum(), formulaDTO.getPageSize());
            IPage<FormulaVO> resultPage = formulaMapper.list((Page<FormulaVO>) page, formulaDTO);

            // 输出详细的查询结果到控制台
            resultPage.getRecords().forEach(record -> {
                logger.info("FormulaVO: {}", record);
            });

            return resultPage;
        } catch (Exception e) {
            logger.error("查询公式列表失败", e);
            return new Page<>();
        }
    }
}

